<?php session_start(); ?>
<?php require("../libraries/config.php"); ?>
<?php require("../libraries/database.php"); ?>
<?php require("libraries/users.php"); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Administrator</title>
<style>
fieldset legend{
	color:red;
	}
</style>
<script type="text/javascript" src="../scripts/jquery-1.11.1.min.js">
</script>
<script type="text/javascript">
	$(document).ready(function(){
        $("input[type=submit]").click(function(){
				name = $("#name").val();
				pass = $("#pass").val();
				errors = $("#errors");
				if(name == "" || pass == ""){
					errors.html("Nhập thông tin vào đi");
					return false;
				}else{
					$.ajax({
						"url" : "process.php",
						"type" : "post",
						"data" : "user="+name+"&pass="+pass,
						"async": false,
						success: function(result){
							//alert(result);
							//return false;
							if(result == 1){
								errors.html("Vui lòng nhập đúng thông tin");
								return false;
							}else{
								errors.html("Đang đăng nhập cứ từ từ...");
								setTimeout(function() {
									window.location = "index.php";
								},3000);
							}
						}
					});
				}
			});
    });
</script> 
</head>

<body>
<div id="errors" style="color:#F00"></div>
<form action="javascript:void(0)" method="post">
<div id="field" style="width:400px;margin:auto">
 <fieldset>
  <legend>Đăng nhập</legend>
  <table>
  <tr>
  <td>Username </td><td><input type="text" name="name" id="name"></td>
  </tr>
  <tr>
  <td>Password </td><td><input type="password" name="pass" id="pass"></td>
  </tr>
  <tr>
  <td></td>
  <td><input type="submit" value="Đăng nhập" name="ok" /></td>
  </tr>
  </table>
 </fieldset>
 </div>
</form>
</body>
</html>